package com.test.spring.test.xml.bean.selfLabel;

import com.test.spring.test.xml.bean.User;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;

/**
 * 解析自定义xml文件用的
 */
public class UserBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser {

	@SuppressWarnings("rawtypes")
	protected Class getBeanClass(Element element) {
		return User.class;
	}

	protected void doParse(Element element, BeanDefinitionBuilder builder) {
		String userName = element.getAttribute("userName");
		String email = element.getAttribute("email");
		if (StringUtils.hasText(userName)) {
			builder.addPropertyValue("userName", userName);
		}
		if (StringUtils.hasText(email)){
			builder.addPropertyValue("email", email);
		}

	}
}
